﻿#region Copyright Notice
// This file is part of GestionPedago.
// <description>
// Copyright (C) 2012 ENI Ecole Informatique
// 
// GestionPedago is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// <program> is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using GestionPedago.EntityContext;
using GestionPedago.Services.Framework;
using GestionPedago.Services.ES.Modele;

namespace GestionPedago.Services.Mapping
{
    /// <summary>
    /// Classe de mapping Entity<->ES de l'objet UniteFormation
    /// </summary>
    public class UniteFormationMappeur : IMappeur<UniteFormation, UniteFormationES>
    {
        /// <summary>
        /// Constructeur
        /// </summary>
        public UniteFormationMappeur() { }

        /// <summary>
        /// Mapping Entity -> ES
        /// </summary>
        /// <param name="entity">L'entity à mapper</param>
        /// <returns>L'ES obtenu</returns>
        public UniteFormationES Entity2ES(UniteFormation entity)
        {
            UniteFormationES retour = new UniteFormationES();
            retour.Libelle = entity.Libelle;
            retour.DureeEnHeures = entity.DureeEnHeures;
            retour.DateCreation = entity.DateCreation;
            retour.DureeEnSemaines = entity.DureeEnSemaines;
            retour.DateModif = entity.DateModif;
            retour.LibelleCourt = entity.LibelleCourt;
            retour.IdUniteFormation = entity.IdUniteFormation;
            retour.Archiver = entity.Archiver;
            //TODO implémenter mapping Entity<->ES manuellement ! : UniteParFormation
            return retour;
        }

        /// <summary>
        /// Mapping ES -> Entity
        /// </summary>
        /// <param name="es">L'ES à mapper</param>
        /// <returns>L'entity obtenu</returns>
        public UniteFormation ES2Entity(UniteFormationES es)
        {
            UniteFormation retour = new UniteFormation();
            retour.Libelle = es.Libelle;
            retour.DureeEnHeures = es.DureeEnHeures;
            retour.DateCreation = es.DateCreation;
            retour.DureeEnSemaines = es.DureeEnSemaines;
            retour.DateModif = es.DateModif;
            retour.LibelleCourt = es.LibelleCourt;
            retour.IdUniteFormation = es.IdUniteFormation;
            retour.Archiver = es.Archiver;
            //TODO implémenter mapping Entity<->ES manuellement ! : UniteParFormation
            if (!EntityStateChecker.IsDetached(retour))
            {
                EntityConnection.GetContext().UniteFormation.ApplyCurrentValues(retour);
            }
            else
            {
                EntityConnection.GetContext().UniteFormation.Attach(retour);
            }
            return retour;
        }
    }
}
